<?php

namespace App\Http\Requests\auth;

use Illuminate\Foundation\Http\FormRequest;

class AuthRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        $action = request()->getPathInfo();

        $basics = [

        ];


        switch ($action){
            case '/v1/auth/code':
                $rule = [
                    'phone'   =>  'required|phone',
                    'code' => 'required|code'
                ];
                break;
            case '/v1/auth/register':
                $rule = [
                    'code'     => 'required|code',
                    'phone'    => 'required|phone|unique:users',
                    'password' => 'required|alpha_dash|between:6,24',
                    'level' => "in:1,2,3"
                ];
                break;
            case '/v1/auth/third':
            case '/v1/user/bind_wx':
                $rule = [
                    'open_id'  => 'required',
                    'app_type' => "in:1,2,3"
                ];
                break;
            case '/v1/auth/resetPassword':
                $rule = [
                    'phone'   =>  'required|phone',
                    'password' => 'required|alpha_dash|between:8,24'
                ];
                break;
            default :
                $rule = [
                    'phone'   =>  'required',
                    'password' => 'required',
                ];
               break;

        }

        return array_merge($basics,$rule);
    }

    public function messages()
    {
        return [
            'phone.unique' => '手机号码已注册!'
        ];
    }

}
